package com.tudouji.project.organization.service.impl;

import java.util.List;

import com.tudouji.common.utils.DateUtils;
import com.tudouji.common.utils.IdUtils;
import com.tudouji.common.utils.SecurityUtil;
import com.tudouji.common.utils.SecurityUtils;
import com.tudouji.project.system.domain.SysDept;
import com.tudouji.project.system.domain.SysUser;
import com.tudouji.project.system.mapper.SysDeptMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.tudouji.project.organization.mapper.ChannelMapper;
import com.tudouji.project.organization.domain.Channel;
import com.tudouji.project.organization.service.IChannelService;

/**
 * 渠道管理Service业务层处理
 *
 * @author wf
 * @date 2021-04-21
 */
@Service
public class ChannelServiceImpl implements IChannelService {
    @Autowired
    private ChannelMapper channelMapper;

    @Autowired
    private SysDeptMapper deptMapper;

    /**
     * 查询渠道管理
     *
     * @param guid 渠道管理ID
     * @return 渠道管理
     */
    @Override
    public Channel selectChannelById(String guid) {
        return channelMapper.selectChannelById(guid);
    }

    /**
     * 查询渠道管理列表
     *
     * @param channel 渠道管理
     * @return 渠道管理
     */
    @Override
    public List<Channel> selectChannelList(Channel channel) {
        return channelMapper.selectChannelList(channel);
    }

    /**
     * 新增渠道管理
     *
     * @param channel 渠道管理
     * @return 结果
     */
    @Override
    public int insertChannel(Channel channel) {
        SysUser user=SecurityUtils.getLoginUser().getUser();
        channel.setGuid(IdUtils.fastSimpleUUID());
        channel.setCreatetime(DateUtils.getNowDate());
        channel.setOperatorid(user.getGuid());
        channel.setCreateBy(user.getUserId());
        channel.setOperatorid(user.getNickName());
        channel.setLastupdate(DateUtils.getNowDate());
        channel.setStatus(1);
        SysDept dept=deptMapper.selectDeptByGuid(channel.getDepartid());
        channel.setDeptId(dept.getDeptId());
        return channelMapper.insertChannel(channel);
    }

    /**
     * 修改渠道管理
     *
     * @param channel 渠道管理
     * @return 结果
     */
    @Override
    public int updateChannel(Channel channel) {
        channel.setLastupdate(DateUtils.getNowDate());
        SysDept dept=deptMapper.selectDeptByGuid(channel.getDepartid());
        channel.setDeptId(dept.getDeptId());
        return channelMapper.updateChannel(channel);
    }

    /**
     * 批量删除渠道管理
     *
     * @param guids 需要删除的渠道管理ID
     * @return 结果
     */
    @Override
    public int deleteChannelByIds(String[] guids) {
        return channelMapper.deleteChannelByIds(guids);
    }

    /**
     * 删除渠道管理信息
     *
     * @param guid 渠道管理ID
     * @return 结果
     */
    @Override
    public int deleteChannelById(String guid) {
        return channelMapper.deleteChannelById(guid);
    }
}
